﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Collections.Generic;

using Jzy.BLL.DocManger;
using Jzy.Model.DocManger;

using Frame.Lib.Common;
using Frame.Lib.Enums;
using Frame.Lib.Core.Right;
using Frame.Lib.Utilities;
using Frame.Lib.Core.Tree;
using Jzy.DAL;

public partial class DocManger_DirTree :PageBase
{
    private DirBO dir = new DirBO();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HtmlGenericControl body = (HtmlGenericControl)this.Master.Page.Form.FindControl("body");
            body.Attributes.Add("class", "left_body_bg");
            
            JSUtil.SetDivHeight("tree", 30);
            lnkManage.Visible = false;
            BindTree();
            if (tvDir.Nodes.Count > 0)
            {
                string strFirstUpperID = tvDir.Nodes[0].Value;
                JSUtil.ExcuteJS("parent.document.getElementById('frameMain').src='" + GlobalVar.WebAppPath + "DocManager/Document/List.aspx?DirID=" + this.Encrypt(strFirstUpperID) + "';");


                DirInfo info = dir.GetInfo(strFirstUpperID);
                RecordRightBO right = new RecordRightBO(OTableName.DocDirRight);
                List<int> lstBindIDs = right.GetBindIDs(AppSession.UserID, RecordRightName.Manage, RightOwnerType.User);
                if (AppSession.UserID == Constants.ADMIN_ID || AppSession.UserID == info.CreatorID || lstBindIDs.Contains(info.ID))
                {
                    lnkManage.Visible = true;
                }
                else
                {
                    lnkManage.Visible = false;
                }
            }
        }      
    }

    private void BindTree()
    {
        List<string> lstExpendIDs = new List<string>();
        TreeBO<TreeInfo>.SetExpend(tvDir, lstExpendIDs);

        RecordRightBO right = new RecordRightBO(OTableName.DocDirRight);
        List<int> lstDirIDs = right.GetBindIDs(AppSession.UserID, RecordRightName.Browse, RightOwnerType.User);
        dir.BindTreeView(tvDir, lstDirIDs,false);

        TreeBO<TreeInfo>.RestoreExpend(tvDir, lstExpendIDs);


        TreeNode node = new TreeNode("高级检索", "search");
        node.NavigateUrl = "Document/Search.aspx";
        node.Target = "frameMain";
        node.ImageUrl = "../common/images/icons/page_find.gif";
        tvDir.Nodes.Add(node);


       
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindTree();
    }
}
